<!-- Add Modal //-->
<div id="addModal" class="reveal-modal medium" data-reveal>
	<span id="loadingKelas" style="display:none;">Sedang memproses..</span>
	<span id="errorkelas" style="display:none;color:red;">Ma'af, tidak dapat memuat</span>
	<div id="add_tholabah_modal"></div>
</div>
<!-- End Add Modal //-->

<!-- Delete Modal //-->
<div id="delModal" class="reveal-modal tiny" data-reveal>
	<p class="p-modal">
	<span id="hpid" class="hpid var-modal" style="display:none;"></span>
	<span id="id_a_non_sy" style="display:none;"><?php echo $id_a_non_sy = $this->security->xss_clean($this->uri->segment(3));?></span>
	Yakin ingin menghapus <span class="nama var-modal"></span> dari tagihan <span class="2nd var-modal"></span> sebesar <span class="3rd var-modal"></span> ?</p><br/><br/>
	<span id="loading" style="display:none;">Sedang memproses..</span>
	<span id="error" style="display:none;color:red;">Ma'af, tholabah tidak bisa dihapus</span>
	<span class="pull-right">
		<button class="deleteUrl btn btn-xs tmb-utama" id="hapusBagiNonSy"> Yakin</button> 
		<button class="btn tmb-kedua close-reveal-modal close-modal"> Tidak</button></span>
</div>
<!-- End Delete Modal //-->

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default kotakwidget">
			<div class="panel-heading kepalakotakwidget">
				Tagihan <?php foreach ($list_detailTag as $row) {$besar_tagihan = formatRupiah($row->besar_bayar); $id_m_j_pendidikan = $row->id_m_j_pendidikan; $nama_tagihan = $row->nama_non_sy; echo $nama_non_sy = $row->nama_non_sy.' sebesar '.$besar_bayar = formatRupiah($row->besar_bayar).' bagi tholabah jenjang '.$jenjang = $row->j_pendidikan;?>
				<div>
					<span class="wali_kelas">
						Masa Bayar: <?php echo hijriah($row->mulai_bayar).' sd '.hijriah($row->akhir_bayar); ?>.
						Telah dibebankan kepada <span id="jml"><?php echo $row->jml;}?></span> tholabah
					</span>
				
					<span class="pull-right tmb_panel_head">
						<button onClick="add_tholabah('<?php echo id_ta_aktif();?>','<?php echo $id_m_j_pendidikan;?>','<?php echo $id_a_non_sy;?>')" data-reveal-id="addModal" data-reveal class="btn btn-sm tmb-tambah tmb-utama"><i class="fa fa-plus"></i> Tambah</button>
					</span>	
				</div>			
			</div>
				
				<div class="panel-body">
					<div class="row">
						<div class="col-md-12">
							<div id="contentBagiNonSy">
							<table class="table table-condensed" id="th_ajaran">
							  <thead>
								<tr>
									<th width="30">#</th>
									<th width="80">NIT</th>
									<th>Nama Lengkap</th>
									<th>Jenis Kelamin</th>
									<th>Alamat</th>
									<th>Kelas</th>
								</tr>
							  </thead>
							  <tbody>
								<?php 
									if(count($list)>0){
										$i = 1; 
										foreach ($list as $row) {
								?>
								<tr class="hover">
									<td><?php echo $i++ ?></td>
									<td><?php echo $row->id_m_tholabah; ?></td> 
									<td><?php echo $row->nama_lengkap; ?></td> 
									<td><?php echo $row->jk; ?></td>
									<td><?php echo $row->alamat; ?></td>
									<td>
										<?php echo $row->kelas; ?>
										<a class="editorLink pull-right" data-reveal-id="delModal" nama="<?php echo $row->nama_lengkap; ?>" 2nd="<?php echo $nama_tagihan;?>" 3rd="<?php echo $besar_tagihan;?>" hpid="<?php echo $row->id_b_non_sy;?>" data-reveal><span class="glyphicon glyphicon-floppy-remove"></span></a>
									</td>
								</tr>
								<?php
										}
									}else{
								?>
								<tr>
									<td colspan="6"><center>Belum ada tholabah <?php echo $jenjang;?> dibebani tagihan <?php echo $nama_non_sy;?></center></td>
								</tr>
								<?php
									}
								?>
							  </tbody>
							</table>
							</div>
						</div>
					</div>
				</div>
		</div>
	</div>	
</div>
<!-- /#page-wrapper -->
<script>
// Add Tholabah, Memunculkan modal untuk memilih tholabah
function add_tholabah(id_m_th_ajaran,id_m_j_pendidikan,id_a_non_sy){
	$.ajax({
		type: "POST",
			data: "id_m_th_ajaran="+id_m_th_ajaran+"&id_m_j_pendidikan="+id_m_j_pendidikan+"&id_a_non_sy="+id_a_non_sy,
			url : "<?php echo site_url(); ?>b_non_sy/add_tholabah",				
			cache: false,
			beforeSend: function(){
				$('#loadingKelas').show();
				$('#errorKelas').hide();
			}, 
			success: function(response){
				$('#add_tholabah_modal').html(response);
				$('#loadingKelas').hide();					
			}, 
			error:function(){
				$('#errorKelas').show();
				$('#loadingKelas').hide();
			}
	});
	return false;
}
// Ajax Complete
$(document).ajaxComplete(function(){
	// Combo pilih nama kelas
	$("#id_m_kelas").change(function(){
		var id_m_th_ajaranSkrg = $("#id_m_th_ajaranSkrg").val();
		var id_m_j_pendidikan = $("#id_m_j_pendidikan").val();
		var id_m_kelas = $("#id_m_kelas").val();		
		var id_a_non_sy = $("#id_a_non_sy").text();	
		$.ajax({
			type: "POST",				
			data: "id_m_th_ajaranSkrg="+id_m_th_ajaranSkrg+"&id_m_j_pendidikan="+id_m_j_pendidikan+"&id_m_kelas="+id_m_kelas+"&id_a_non_sy="+id_a_non_sy,
			url : "<?php echo site_url(); ?>b_non_sy/list_tholabah_modal",
			beforeSend: function(){
				$('#loadingTholabah').show();
				$('#errorTholabah').hide();
			},
			success: function(msg){
				$('#loadingTholabah').hide();
				$('#list_tholabah_modal').html(msg);
			},
			error:function(){
				$('#loadingTholabah').hide();
				$('#errorTholabah').show();
			}
		});		
		stopPropagation();		
	});

	// Checkbox dalam bentuk table row
    $('.diklik tr').click(function(event) {
        if (event.target.type !== 'checkbox') {
            $(':checkbox', this).trigger('click');
        }
    });

    $("input[type='checkbox']").change(function (e) {
        if ($(this).is(":checked")) {
            $(this).closest('tr').addClass("highlight_row");
        } else {
            $(this).closest('tr').removeClass("highlight_row");
        }
    });	

    $('#SaveBagiNonSy').bind('submit', function(event) {
		var link = $(this).attr('action');
		var id_a_non_sy = $("#id_a_non_sy").text();
		$.ajax({
			url: link,
			type: "POST",
			data: $(this).serialize(),
			cache: false,
			beforeSend: function(){
				$('#errorAdd').hide();
				$('#loadingAdd').show();
			},          
			success: function() {
				var $container = $("#contentBagiNonSy");
				$container.load("<?php echo site_url(); ?>b_non_sy/refresh/"+id_a_non_sy);

				var $container = $("#jml");
				$container.load("<?php echo site_url(); ?>b_non_sy/refresh_jml/"+id_a_non_sy);
				
				$('#loadingAdd').hide();
				$('#addModal').foundation('reveal', 'close');
			},
			error:function(){
				$('#loadingAdd').hide();
				$('#errorAdd').show();
			}
		});
		return false; // dont post it automatically
	});

});
// Delete
$("#hapusBagiNonSy").on("click", function(){
	var id_b_non_sy = $("#hpid").text();
	var id_a_non_sy = $("#id_a_non_sy").text();
	$.ajax({
		type: "POST",
		data: "id_b_non_sy="+id_b_non_sy,
		url : "<?php echo site_url(); ?>b_non_sy/delete",				
		cache: false,
		beforeSend: function(){
			$('#loading').show();
			$('#error').hide();
		}, 
		success: function(){
			var $container = $("#contentBagiNonSy");
			$container.load("<?php echo site_url(); ?>b_non_sy/refresh/"+id_a_non_sy);

			var $container = $("#jml");
			$container.load("<?php echo site_url(); ?>b_non_sy/refresh_jml/"+id_a_non_sy);
			
			$('#loading').hide();
			$('#delModal').foundation('reveal', 'close');					
		}, 
		error:function(){
			$('#error').show();
			$('#loading').hide();
		}
	});
	return false; 
});
</script>